<template>
  <n-modal style="width: 600px;" v-model:show="curShow" preset="card"
           @after-enter="getInfo">
    <div>
      <slot name="head"></slot>
    </div>
    <div v-if="info">
      <n-descriptions label-placement="left" :column="2" bordered >
        <n-descriptions-item label="用户名">
          {{ info.username }}
        </n-descriptions-item>
        <n-descriptions-item label="工号" v-if="props.data.status===33">
          {{ info.jobNum }}
        </n-descriptions-item>
        <n-descriptions-item label="编号" v-else-if="props.data.status===44">
          {{ info.specialistNum }}
        </n-descriptions-item>
        <n-descriptions-item label="姓名">
          {{ info.name }}
        </n-descriptions-item>
        <n-descriptions-item label="性别">
          {{ info.sex }}
        </n-descriptions-item>
        <n-descriptions-item label="科室" v-if="props.data.status===33">
          {{ info.department }}
        </n-descriptions-item>
        <n-descriptions-item label="工作单位" v-else-if="props.data.status===44">
          {{ info.workUnit }}
        </n-descriptions-item>
        <n-descriptions-item label="手机">
          {{ info.phone }}
        </n-descriptions-item>
      </n-descriptions>
    </div>
    <n-empty v-else></n-empty>
    <template #footer>
      <div>
        <slot name="tail"></slot>
      </div>
    </template>

  </n-modal>
</template>

<script setup lang="ts">
import {computed, ref} from "vue";
import api from "@/api"

const props = defineProps({
  data: {
    type: Object,
    default: {}
  },
  show: {
    type: Boolean,
    default: false
  }
})
const emits = defineEmits(['update:show'])
const info = ref()
const getInfo = () => {
  let func: any
  if (props.data.status == 33) {
    func = api.nurse.infoByUsername({
      username: props.data.username
    })
  } else if (props.data.status == 44) {
    func = api.specialist.infoByUsername({
      username: props.data.username
    })
  } else if (props.data.status == 55) {
    func = api.admin.infoByUsername({
      username: props.data.username
    })
  }
  func.then((res: { data: { code: number; data: any; }; }) => {
    if (res && res.data.code === 0) {
      info.value = res.data.data
    }
  })

}

const curShow = computed({
  get() {
    return props.show
  },
  set(val) {
    emits('update:show', val)
  }
})
</script>

<style scoped>

</style>